unit GLGUIKeys;

interface

uses
  SysUtils,
  VectorTypes,
  GLSGenerics;

type
  TGLGUIKey = class
  private
    FName : String;
    FFormatSettings: TFormatSettings;
    function GetName: String; virtual;
    procedure SetName(AName: String); virtual;
    function GetDecimalSeparator: Char;
    procedure SetDecimalSeparator(AValue: Char);
  public
    procedure SetValue(AValue : Single); overload; virtual; abstract;
    procedure SetValue(AValue : Integer); overload; virtual; abstract;
    procedure SetValue(AValue : TVector2f); overload; virtual; abstract;
    procedure SetValue(AValue : TVector3f); overload; virtual; abstract;
    procedure SetValue(AValue : TVector4f); overload; virtual; abstract;
    procedure SetStringValue(AValue: String); overload; virtual; abstract;
    procedure AssignTo(var AValue : Single); overload; virtual; abstract;
    procedure AssignTo(var AValue : Integer); overload; virtual; abstract;
    procedure AssignTo(var AValue : TVector2f); overload; virtual; abstract;
    procedure AssignTo(var AValue : TVector3f); overload; virtual; abstract;
    procedure AssignTo(var AValue : TVector4f); overload; virtual; abstract;
    function GetInt: Integer; virtual; abstract;
    function GetFloat: Single; virtual; abstract;
    function GetVec2f: TVector2f; virtual; abstract;
    function GetVec3f: TVector3f; virtual; abstract;
    function GetVec4f: TVector4f; virtual; abstract;
    function ToString: String; override; abstract;
    property Name: String read GetName write SetName;
    property DecimalSeparator: Char read GetDecimalSeparator
      write SetDecimalSeparator;
  end;

  TGLGUIKeyFloat = class(TGLGUIKey)
    FValue : Single;
    procedure SetValue(AValue : Single); override;
  public
    function GetFloat: Single; override;
    function ToString: String; override;
    procedure AssignTo(var AValue : Single); override;
    procedure SetStringValue(AValue: String); override;
    property Value: Single read GetFloat write SetValue;
  end;

  TGLGUIKeyInt = class(TGLGUIKey)
  protected
    FValue : Integer;
    procedure SetValue(AValue : Integer); override;
  public
    function GetInt: Integer; override;
    function ToString: String; override;
    procedure SetStringValue(AValue: String); override;
    property Value: Integer read GetInt write SetValue;
  end;

  TGLGUIKeyVec2f = class(TGLGUIKey)
  protected
    FValue : TVector2f;
    procedure SetValue(AValue : TVector2f); override;
  public
    function GetVec2f: TVector2f; override;
    function ToString: String; override;
    procedure SetStringValue(AValue: String); override;
    property Value: TVector2f read GetVec2f write SetValue;
  end;

  TGLGUIKeyVec3f = class(TGLGUIKey)
  protected
    FValue : TVector3f;
    procedure SetValue(AValue : TVector3f); override;
  public
    function GetVec3f: TVector3f; override;
    function ToString: String; override;
    procedure SetStringValue(AValue: String); override;
    property Value: TVector3f read GetVec3f write SetValue;
  end;

  TGLGUIKeyVec4f = class(TGLGUIKey)
  protected
    FValue : TVector4f;
    procedure SetValue(AValue : TVector4f); override;
  public
    function GetVec4f: TVector4f; override;
    function ToString: String; override;
    procedure SetStringValue(AValue: String); override;
    property Value: TVector4f read GetVec4f write SetValue;
  end;

  TGLGUIKeyClass = class of TGLGUIKey;

  TGLGUIKeysList = class(GList<TGLGUIKey>)
    function Find(AName: String): TGLGUIKey;
  end;
implementation

uses GLGUIUtils;

function TGLGUIKey.GetName: String;
begin
  Result := FName;
end;

procedure TGLGUIKey.SetName(AName: String);
begin
  FName := AName;
end;

procedure TGLGUIKey.SetDecimalSeparator(AValue: Char);
begin
  FFormatSettings.DecimalSeparator := AValue;
end;

function TGLGUIKey.GetDecimalSeparator: Char;
begin
  Result := FFormatSettings.DecimalSeparator;
end;

//
//TGLGUIKeyFloat
//

function TGLGUIKeyFloat.GetFloat: Single;
begin
  Result := FValue;
end;

procedure TGLGUIKeyFloat.SetValue(AValue : Single);
begin
  FValue := AValue;
end;

function TGLGUIKeyFloat.ToString: String;
begin
  Result := SysUtils.FloatToStr(FValue, FFormatSettings);
end;

procedure TGLGUIKeyFloat.AssignTo(var AValue : Single);
begin
  AValue := Value;
end;

procedure TGLGUIKeyFloat.SetStringValue(AValue: String);
begin
  FValue := SysUtils.StrToFloat(AValue, FFormatSettings);
end;

//
//TGLGUIKeyInt
//

function TGLGUIKeyInt.GetInt: Integer;
begin
  Result := FValue;
end;

procedure TGLGUIKeyInt.SetValue(AValue : Integer);
begin
  FValue := AValue;
end;

function TGLGUIKeyInt.ToString: String;
begin
  Result := IntToStr(FValue);
end;

procedure TGLGUIKeyInt.SetStringValue(AValue: String);
begin
  FValue := StrToInt(AValue);
end;

//
//TGLGUIKeyIVec2f
//

function TGLGUIKeyVec2f.GetVec2f: TVector2f;
begin
  Result := FValue;
end;

procedure TGLGUIKeyVec2f.SetValue(AValue: TVector2f);
begin
  FValue := AValue;
end;

function TGLGUIKeyVec2f.ToString: String;
begin
  Result := Vector2fToString(FValue);
end;

procedure TGLGUIKeyVec2f.SetStringValue(AValue: String);
begin
  FValue := StringToVector2f(AValue);
end;

//
//TGLGUIKeyIVec3f
//

function TGLGUIKeyVec3f.GetVec3f: TVector3f;
begin
  Result := FValue;
end;

procedure TGLGUIKeyVec3f.SetValue(AValue: TVector3f);
begin
  FValue := AValue;
end;

function TGLGUIKeyVec3f.ToString: String;
begin
  Result := Vector3fToString(FValue);
end;

procedure TGLGUIKeyVec3f.SetStringValue(AValue: String);
begin
  FValue := StringToVector3f(AValue);
end;

//
//TGLGUIKeyIVec4f
//

function TGLGUIKeyVec4f.GetVec4f: TVector4f;
begin
  Result := FValue;
end;

procedure TGLGUIKeyVec4f.SetValue(AValue: TVector4f);
begin
  FValue := AValue;
end;

function TGLGUIKeyVec4f.ToString: String;
begin
  Result := Vector4fToString(FValue);
end;

procedure TGLGUIKeyVec4f.SetStringValue(AValue: String);
begin
  FValue := StringToVector4f(AValue);
end;

function TGLGUIKeysList.Find(AName: String): TGLGUIKey;
var
  i: Integer;
  vKey: TGLGUIKey;
begin
  Result := nil;
  for i := 0 to Self.Count-1 do
  begin
    vKey := Self.Items[i];
    if SameStr(vKey.Name, AName) then
    begin
      Result := vKey;
      Exit;
    end;
  end;
end;

end.
